from json import dumps

from flask_restful.representations.json import output_json
from flask import current_app, make_response


def custom_uotput_json(data, code , headers=None):
    """自定义返回的json格式"""
    settings = current_app.config.get('RESTFUL_JSON', {})
    if current_app.debug:
        settings.setdefault('indent', 4)


    #重写返回的data格式
    if 'message' not in data:
        data = {
            "message":"ok",
            "data":data
        }
    dumped = dumps(data, **settings) + "\n"

    resp = make_response(dumped, code)
    resp.headers.extend(headers or {})
    return resp